import {post, get} from '../utils/';
import * as types from '../constants/actTypes';


/**
 * 获取活动列表
 * */
export function fetchActList(data) {
    return (dispatch) => {
        return post('/api/activity/event/list', data).then(
            response => dispatch({
                type: types.FETCH_ACT_LIST,
                actList: response.data.array
            }),
            error => dispatch({
                type: types.FETCH_ACT_LIST_FAILED,
                error
            })
        )

    }
}

/**
 * 获取活动详情
 * @param {number} id 活动id
 * */
export function fetchActListDetail(id) {
    let data = {
        eventId: id
    };
    return (dispatch) => {
        return post('/api/activity/one', data).then(
            response => dispatch({
                type: types.FETCH_ACT_LIST_DETAIL,
                data: response
            }),
            error => dispatch({
                type: types.FETCH_ACT_LIST_DETAIL_FAILED,
                error
            })
        )

    }
}

/**
 * 获取活动详情 个人
 * @param {number} id 活动id
 * */
export function fetchActListDetailPerson(id) {
    let data = {
        eventId: id
    };
    return (dispatch) => {
        return post('/api/activity/event/one', data).then(
            response => dispatch({
                type: types.FETCH_ACT_LIST_DETAIL_PERSON,
                data: response
            }),
            error => dispatch({
                type: types.FETCH_ACT_LIST_DETAIL_PERSON_FAILED,
                error
            })
        )

    }
}
/**
 * 报名活动
 * @param {number} id 活动id
 * @param {string} name 活动id
 * @param {string} phone 活动id
 * */
export function applyAct(id, name, phone) {
    let data = {
        eventId: id,
        name: name,
        phone: phone
    };
    return (dispatch) => {
        return post('/api/activity/one', data).then(
            response => dispatch({
                type: types.APPLY_ACT,
                curAct: response.data
            }),
            error => dispatch({
                type: types.APPLY_ACT_FAILED,
                error
            })
        )

    }
}
/**
 * 报名志愿者
 * @param {number} id 活动id
 * @param {string} name 活动id
 * @param {string} phone 活动id
 * */
export function applyVol(id, name, phone) {
    let data = {
        eventId: id,
        name: name,
        phone: phone
    };
    return (dispatch) => {
        return post('/api/activity/event/volunteer/add', data).then(
            response => dispatch({
                type: types.APPLY_VOL,
                response: response
            }),
            error => dispatch({
                type: types.APPLY_VOL_FAILED,
                error
            })
        )

    }
}


/**
 * 获取场馆信息
 * */
export function fetchRoomInfo(data) {
    return (dispatch) => {
        return post('/api/room/one',data).then(
            response => dispatch({
                type: types.FETCH_ROOM_INFO,
                data: response
            }),
            error => dispatch({
                type: types.FETCH_ROOM_INFO_FAILED,
                error
            })
        )
    }
}

/**
 * 关注场馆
 * */
export function followRoom(data) {
    return (dispatch) => {
        return post('/api/room/follower/add',data).then(
            response => dispatch({
                type: types.FOLLOW_ROOM,
                data: response,
                isFollow: 1
            }),
            error => dispatch({
                type: types.FOLLOW_ROOM_FAILED,
                error
            })
        )
    }
}

/**
 * 取消关注场馆
 * */
export function cancelFollowRoom(data) {
    return (dispatch) => {
        return post('/api/room/follower/cancel',data).then(
            response => dispatch({
                type: types.CANCEL_FOLLOW_ROOM,
                data: response,
                isFollow: 0
            }),
            error => dispatch({
                type: types.CANCEL_FOLLOW_ROOM_FAILED,
                error
            })
        )
    }
}

/**
 * 获取场馆粉丝列表
 * */
export function fetchRoomFans(data) {
    return (dispatch) => {
        return post('/api/room/follower/list',data).then(
            response => dispatch({
                type: types.FETCH_ROOM_FANS_LIST,
                fansList: response.data.array,
                code: response.code
            }),
            error => dispatch({
                type: types.FETCH_ROOM_FANS_LIST_FAILED,
                error
            })
        )
    }
}


/**
 * 获取场馆数据 H5 数据图表
 * */
export function fetchRoomData(data) {
    return (dispatch) => {
        return post('/api/room/data',data).then(
            response => dispatch({
                type: types.FETCH_ROOM_DATA,
                data: response
            }),
            error => dispatch({
                type: types.FETCH_ROOM_DATA_FAILED,
                error
            })
        )
    }
}

/**
 * 获取组织数据 H5 数据图表
 * */
export function fetchOrgData(data) {
    return (dispatch) => {
        return post('/api/organize/data',data).then(
            response => dispatch({
                type: types.FETCH_ORG_DATA,
                data: response
            }),
            error => dispatch({
                type: types.FETCH_ORG_DATA_FAILED,
                error
            })
        )
    }
}
